# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=cbor-tool
pkgver=0.2.2.0
pkgrel=62
pkgdesc="A tool for manipulating CBOR"
url="https://github.com/well-typed/cborg"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-aeson-pretty' 'haskell-cborg' 'haskell-cborg-json'
         'haskell-scientific' 'haskell-unordered-containers' 'haskell-vector')
makedepends=('ghc' 'uusi')
source=("https://hackage.haskell.org/packages/archive/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('d720f1caa98153bebea7ade4a0f1f53010a5febd2d53925c945e26f8c3b75667')

prepare() {
  cd $pkgname-$pkgver
  uusi -u aeson -u vector $pkgname.cabal
}

build() {
  cd $pkgname-$pkgver

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --datasubdir=haskell-cbor-tool --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie' 

  runhaskell Setup build $MAKEFLAGS
}

check() {
  cd $pkgname-$pkgver
  runhaskell Setup test --show-details=direct
}

package() {
  cd $pkgname-$pkgver

  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE.txt
}
